package com.dwms.controller;

import com.dwms.entity.PageResponse;
import com.dwms.entity.QueryRequest;
import com.dwms.entity.Result;
import com.dwms.entity.declare.taxRate.request.TaxRateQueryRequest;
import com.dwms.entity.declare.taxRate.request.TaxRateRequest;
import com.dwms.entity.declare.taxRate.response.TaxRateResponse;
import com.dwms.feign.declare.TaxRateFeignClient;
import com.dwms.utils.WebUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: TaxRateController
 * @Description: TaxRate
 * @Create 2025-09-06 14:19:00
 * @Author WH
 * @Since 1.0.0
**/
@Tag(name = "商品税率管理")
@RestController
@RequestMapping(value = "/declare/taxRate")
@RequiredArgsConstructor
public class TaxRateController {

    private final HttpServletRequest request;
    private final TaxRateFeignClient taxRateFeignClient;

    /**
     * 保存
     *
     * @param taxRateRequest
     *          请求参数
     * @return
     */
    @Schema(description = "新增税率")
    @PostMapping("/save")
    public Result save(@RequestBody TaxRateRequest taxRateRequest) {
        WebUtil.getAdminRequest(request,taxRateRequest);
        return taxRateFeignClient.save(taxRateRequest);
    }

    /**
     * 修改
     *
     * @param taxRateRequest
     *          请求参数
     * @return
     */
    @Schema(description = "修改税率")
    @PostMapping("/update")
    public Result update(@RequestBody TaxRateRequest taxRateRequest) {
        WebUtil.getAdminRequest(request,taxRateRequest);
        return taxRateFeignClient.update(taxRateRequest);
    }
    

    /**
     * 分页查询
     *
     * @param query
     *          查询参数
     * @return
     */
    @Schema(description = "分页查询税率")
    @PostMapping("/findPage")
    public Result<PageResponse<TaxRateResponse>> findPage(@RequestBody TaxRateQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return taxRateFeignClient.findPage(query);

    }

    /**
     *  根据ID查询
     *
     * @param query
     *          参数
     * @return
     */
    @Schema(description = "根据ID查询税率")
    @PostMapping("/findById")
    public Result findById(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return this.taxRateFeignClient.findById(query);
    }

    /**
     * 删除
     *
     * @param query
     *          参数
     * @return
     */
    @Schema(description = "删除税率")
    @PostMapping("/delete")
    public Result delete(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return this.taxRateFeignClient.delete(query);
    }

}
